from aerich import Command
from app.core.config import settings, TORTOISE_ORM
import asyncio
import logging

logger = logging.getLogger(__name__)

async def run_migrations():
    """运行数据库迁移"""
    try:
        command = Command(tortoise_config=TORTOISE_ORM, app='models')
        
        # 初始化aerich
        await command.init()
        
        # 执行所有未执行的迁移
        await command.upgrade()
        
        logger.info("Database migrations completed successfully")
    except Exception as e:
        logger.error(f"Error running migrations: {str(e)}")
        raise e 